package com.it.dataservice.user.controller;

import com.it.dataservice.user.config.CaptchaRequest;
import com.it.dataservice.user.config.Verification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Controller
@RestController
public class CaptchaController {
    private final Verification verification;

    @Autowired
    public CaptchaController(Verification verification) {
        this.verification = verification;
    }

    @PostMapping("/api/captcha")
    public ResponseEntity<String> generateCaptcha(@Validated @RequestBody CaptchaRequest request) {
        String yanzhengCode = verification.generateCaptcha();
        System.out.println("手机验证码：" + yanzhengCode);
        return new ResponseEntity<>("验证码已生成", HttpStatus.OK);
    }
}